home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
objects in c ƒ
/
Coord.c
< prev
next >
Wrap
Text File
|
1989-03-01
|
1KB
|
95 lines
/*
* quick-n-dirty class for the Objects-in-C tester
*
* Copyright © John Wainwright 1988
*
*/
#include "oic.h"
#include "generics.h"
typedef struct /* coord IVs */
{
float x;
float y;
} coord_i;
typedef object coord;
class Coord;
/* ------------------------------ Coord Ops -------------------------- */
static coord
_new(self, c, args)
coord self;
coord_i *c;
struct
{
double x;
double y;
} *args;
{
c->x = args->x;
c->y = args->y;
return Super(self);
}
static coord
_offset(self, c, args)
coord self;
coord_i *c;
struct { double dx, dy; } *args;
{
c->x += args->dx;
c->y += args->dy;
return self;
}
static int
_xCoord(self, c)
coord self;
coord_i *c;
{
return c->x;
}
static int
_yCoord(self, c)
coord self;
coord_i *c;
{
return c->y;
}
static string
_replist(self, c)
coord self;
coord_i *c;
{
char s[100];
sprintf(s, "[%.2f, %.2f]", c->x, c->y);
return New(String, s);
}
/* ------------------------------ Init Class ----------------------- */
externGeneric(xCoord, xCoordGeneric)
externGeneric(yCoord, yCoordGeneric)
externGeneric(offset, offsetGeneric)
defGeneric(xCoord, xCoordGeneric, "xCoord")
defGeneric(yCoord, yCoordGeneric, "yCoord")
InitCoordClass()
{
Coord = NewClass(sizeof(coord_i), 0, "Coord", IndexMixin, END);
AddMethods(Coord,
newGeneric, _new,
offsetGeneric, _offset,
repListGeneric, _replist,
xCoordGeneric, _xCoord,
yCoordGeneric, _yCoord,
END);
}